﻿package top.yangyitao.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

import top.yangyitao.model.User;
import top.yangyitao.service.UserService;

@Controller
public class RegisterCheck extends ActionSupport {

	private static final long serialVersionUID = 1L;
	@Resource
	private UserService userService; 
	private User user;
	private String errorMessage;
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public String getErrorMessage() {
		return errorMessage;
	}
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	@Override
	public String execute(){
		switch(userService.userRegisterCheck(user)) {
		case SUCCESS :
			userService.insertUnactiveUser(user);
			errorMessage = "*请在3小时内前往注册邮箱进行注册验证（如未收到邮件请查阅垃圾箱中的邮件）";return SUCCESS;
		case EMAILEXIT : errorMessage = "*该邮箱已被注册!";return ERROR;
		case USERNAMEEXIT : errorMessage = "*该用户名已被注册!";return ERROR;
		case EMAILERROR : errorMessage = "*您输入的邮箱地址不可用!";return ERROR;
		case REREGISTER : 
			userService.insertUnactiveUser(user);
			errorMessage="*重新注册成功，请在三小时内前往注册邮箱进行验证（如未收到邮件请查阅垃圾箱中的邮件）";return SUCCESS;
		}
		return null;
	}
}
